import dva from 'dva';
import './index.css';
import './utils/http'

// 1. Initialize
// 持久化设置
let allState = {}
let unloadListener = !1
const initialState = window.localStorage.getItem('store')
if (initialState && initialState !== '{}') { // get store
    window.localStorage.removeItem('store') // remove store
}
const app = dva({
    initialState: JSON.parse(initialState),
    onStateChange: state => {
        allState = {...state}
        if (!unloadListener) {
            unloadListener = !0
            window.addEventListener('unload', () => {
                window.localStorage.setItem('store', JSON.stringify(allState))
            })
        }
    }
});
// const app = dva();

// 2. Plugins
app.use({});

// 3. Model
app.model(require('./models/News').default);

// 4. Router
app.router(require('./router').default);

// 5. Start
app.start('#root');
